$(function() {
	$('#vue_vm_list').hide();
	var day = $.url().param('day');
	if(isEmpty(day)) {
		alert('缺少日期参数');
		return;
	}
	
	mealsCostRecord_detail_findByDay(day);
});

function getMealsCostRecordSum(baseMealsCostRecordForms) {
	var totalMoney = 0;
	for(var j=0; j<baseMealsCostRecordForms.length; j++) {
		var payMoney = baseMealsCostRecordForms[j].payMoney;
		var quantity = baseMealsCostRecordForms[j].quantity;
		totalMoney += parseFloat((payMoney*quantity).toFixed(2)); //parseFloat必不可少，不然，js会把toFixed的结果当作字符串处理。
	}
	
	return totalMoney;
}

function getMealsCostRecordTotal(todos) {
	var totalMoney = 0;
	for(var i=0; i<todos.length; i++) {
		for(var j=0; j<todos[i].baseMealsCostRecordForms.length; j++) {
			var payMoney = todos[i].baseMealsCostRecordForms[j].payMoney;
			var quantity = todos[i].baseMealsCostRecordForms[j].quantity;
			totalMoney += parseFloat((payMoney*quantity).toFixed(2)); //parseFloat必不可少，不然，js会把toFixed的结果当作字符串处理。
		}
	}
	
	return totalMoney;
}

function mealsCostRecord_detail_findByDay(day) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	
	find_basic_by_json(path+'/mealsCostRecord/findDetailByDay', {day: day}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getMealsCostRecordSum:function(baseMealsCostRecordForms) {
					return getMealsCostRecordSum(baseMealsCostRecordForms);
				},
				getMealsCostRecordTotal:function(todos) {
					return getMealsCostRecordTotal(todos);
				}
			}
		});
		
		$('#vue_vm_list').show();
	});
}